

clear all

*cd 



*This file created the present values under certainty depending on (i) the estimate of water reduction and (ii) the technology lifespan assumption. If you see note "Manual change for (i)" or "Manuel change for (ii)", you should activate one of the available options depending on the estimate of water reduction (i) or lifespan (ii) needed in each case of Table 3. You will find 4 manual changes in lines 46,648,680,714.


use predictedm3_osf.dta, clear

 
local bee_1=6.77 /* basic engineer estimate */
local bee_4=6.77 /* basic engineer estimate */
 

local beep_1=0.277 /* basic engineer estimate */
local beep_4=0.277 /* basic engineer estimate */

local eee_1=5.01 /* enhanced engineer estimate */
local eee_4=5.01 /* enhanced engineer estimate */
   

local eeep_1=0.205 /* enhanced engineer estimate */
local eeep_4=0.205 /* enhanced engineer estimate */

  
local ltitt_1=2.21 
local ltitt_4=2.21 

 
local ltittp_1=0.091 
local ltittp_4=0.091 

*No bonus itt
local ltittnbp_1=0.092 
local ltittnbp_4=0.092 
  
  

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Manual change for (i): Choose the estimate of water reduction

foreach t in 1 4{
foreach y in 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
*gen r`y'`x'_`t'=m3`y'`x'*(1- `ltittnbp_`t'')
gen r`y'`x'_`t'=m3`y'`x'*(1- `ltittp_`t'')
*gen r`y'`x'_`t'=m3`y'`x'*(1- `eeep_`t'')
replace r`y'`x'_`t'=0 if r`y'`x'_`t'<0
}
}
}
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

************************************************************************************************************
*** Adding tariffs to consumption to create predicted savings
************************************************************************************************************

* 2015-2017 Tariffs
********************
local p1=1.2085
local p4=1.2085


*set trace on

foreach q in 1 4{


**** Asada Moracia

foreach y in 2015 2016 2017 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen p`y'`x'_`q'=(2695+155*m3`y'`x') if m3`y'`x'<=10 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*(m3`y'`x' -10)) if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*(m3`y'`x' -30)) if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*30 +200*(m3`y'`x' -60)) if m3`y'`x'>60 & codcom==64

foreach t in 1 4{
	gen p1`y'`x'_`t'_`q'=(2695+155*r`y'`x'_`t') if r`y'`x'_`t'<=10 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*(r`y'`x'_`t' -10)) if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*(r`y'`x'_`t' -30)) if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*30 +200*(r`y'`x'_`t' -60)) if r`y'`x'_`t'>60 & codcom==64
	gen s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==64
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==64
	}
}
}




foreach y in 2015 2016 2017{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3415+160*m3`y'`x') if m3`y'`x' <=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*(m3`y'`x' -10)) if m3`y'`x'>10 & m3`y'`x'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*(m3`y'`x' -30)) if m3`y'`x'>30 & m3`y'`x'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*30 + 195*(m3`y'`x' -60)) if m3`y'`x'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3415+160*r`y'`x'_`t') if r`y'`x'_`t'<=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*(r`y'`x'_`t' -10)) if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*(r`y'`x'_`t' -30)) if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*30 +195*(r`y'`x'_`t' -60)) if r`y'`x'_`t'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	}

}
}

**** Asada Jocotes

foreach y in 2015 2016 2017 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=2745+150*m3`y'`x' if codcom==35

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=2745+150*r`y'`x'_`t' if codcom==35
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==35
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==35
	}
}
}

**** Asada Lomas de Matapalo


foreach y in 2015 2016 2017{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3180+185*m3`y'`x') if m3`y'`x' <=10 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*(m3`y'`x' -10)) if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*20+210*(m3`y'`x' -30)) if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==25 
replace p`y'`x'_`q'=(3180+185*10+195*20+210*30 +225*(m3`y'`x' -60)) if m3`y'`x'>60 & codcom==25 


foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(3180+185*r`y'`x'_`t') if r`y'`x'_`t'<=10 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*(r`y'`x'_`t' -10)) if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*(r`y'`x'_`t' -30)) if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==25 
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*30 +225*(r`y'`x'_`t' -60)) if r`y'`x'_`t'>60 & codcom==25
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if codcom==25
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==25
	}
}

}

**** Asada Pueblo Nuevo

foreach y in 2015 2016 2017{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2800+190*m3`y'`x') if m3`y'`x' <=10 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*(m3`y'`x' -10)) if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*20+215*(m3`y'`x' -30)) if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==47 
replace p`y'`x'_`q'=(2800+190*10+200*20+215*30 +230*(m3`y'`x' -60)) if m3`y'`x'>60 & codcom==47 

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2800+190*r`y'`x'_`t') if r`y'`x'_`t'<=10 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*(r`y'`x'_`t' -10)) if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*(r`y'`x'_`t' -30)) if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==47 
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60)) if r`y'`x'_`t'>60 & codcom==47
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==47
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==47
	}
}
}

**** Asada Santa Rita


foreach y in 2015 2016 2017{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3085+190*m3`y'`x') if m3`y'`x' <=10 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*(m3`y'`x' -10)) if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*(m3`y'`x' -30)) if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*30 +230*(m3`y'`x' -60)) if m3`y'`x'>60 & codcom==32

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3085+190*r`y'`x'_`t') if r`y'`x'_`t'<=10 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*(r`y'`x'_`t' -10)) if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*(r`y'`x'_`t' -30)) if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60)) if r`y'`x'_`t'>60 & codcom==32
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==32
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==32
	}	
}
}


*2018 2019 2020 
***********************


**** Asada Moracia

foreach y in 2018 2019 2020 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen p`y'`x'_`q'=(2695+155*m3`y'`x')*`p`q'' if m3`y'`x'<=10 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*(m3`y'`x' -10))*`p`q'' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*(m3`y'`x' -30))*`p`q'' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*30 +200*(m3`y'`x' -60))*`p`q'' if m3`y'`x'>60 & codcom==64

foreach t in 1 4{
	gen p1`y'`x'_`t'_`q'=(2695+155*r`y'`x'_`t')*`p`q'' if r`y'`x'_`t'<=10 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*(r`y'`x'_`t' -10))*`p`q'' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*(r`y'`x'_`t' -30))*`p`q'' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*30 +200*(r`y'`x'_`t' -60))*`p`q'' if r`y'`x'_`t'>60 & codcom==64
	gen s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==64
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==64
	}
}
}


/*
Paso Tempisque, Chomes, San Blas, Lepanto 

*/

foreach y in 2018 2019 2020{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3415+160*m3`y'`x')*`p`q'' if m3`y'`x' <=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*(m3`y'`x' -10))*`p`q'' if m3`y'`x'>10 & m3`y'`x'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*(m3`y'`x' -30))*`p`q'' if m3`y'`x'>30 & m3`y'`x'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*30 + 195*(m3`y'`x' -60))*`p`q'' if m3`y'`x'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3415+160*r`y'`x'_`t')*`p`q'' if r`y'`x'_`t'<=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*(r`y'`x'_`t' -10))*`p`q'' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*(r`y'`x'_`t' -30))*`p`q'' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*30 +195*(r`y'`x'_`t' -60))*`p`q'' if r`y'`x'_`t'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	}

}
}

**** Asada Jocotes

foreach y in 2018 2019 2020{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2745+150*m3`y'`x')*`p`q'' if codcom==35

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2745+150*r`y'`x'_`t')*`p`q'' if codcom==35
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==35
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==35
	}
}
}

**** Asada Lomas de Matapalo


foreach y in 2018 2019 2020{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3180+185*m3`y'`x')*`p`q'' if m3`y'`x' <=10 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*(m3`y'`x' -10))*`p`q'' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*20+210*(m3`y'`x' -30))*`p`q'' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==25 
replace p`y'`x'_`q'=(3180+185*10+195*20+210*30 +225*(m3`y'`x' -60))*`p`q'' if m3`y'`x'>60 & codcom==25 


foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(3180+185*r`y'`x'_`t')*`p`q'' if r`y'`x'_`t'<=10 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*(r`y'`x'_`t' -10))*`p`q'' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*(r`y'`x'_`t' -30))*`p`q'' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==25 
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*30 +225*(r`y'`x'_`t' -60))*`p`q'' if r`y'`x'_`t'>60 & codcom==25
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if codcom==25
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==25
	}
}

}

**** Asada Pueblo Nuevo

foreach y in 2018 2019 2020{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2800+190*m3`y'`x')*`p`q'' if m3`y'`x' <=10 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*(m3`y'`x' -10))*`p`q'' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*20+215*(m3`y'`x' -30))*`p`q'' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==47 
replace p`y'`x'_`q'=(2800+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q'' if m3`y'`x'>60 & codcom==47 

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2800+190*r`y'`x'_`t')*`p`q'' if r`y'`x'_`t'<=10 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*(r`y'`x'_`t' -10))*`p`q'' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q'' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==47 
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q'' if r`y'`x'_`t'>60 & codcom==47
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==47
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==47
	}
}
}

**** Asada Santa Rita

foreach y in 2018 2019 2020{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3085+190*m3`y'`x')*`p`q'' if m3`y'`x' <=10 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*(m3`y'`x' -10))*`p`q'' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*(m3`y'`x' -30))*`p`q'' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==32 
replace p`y'`x'_`q'=(3085+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q'' if m3`y'`x'>60 & codcom==32

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3085+190*r`y'`x'_`t')*`p`q'' if r`y'`x'_`t'<=10 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*(r`y'`x'_`t' -10))*`p`q'' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q'' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q'' if r`y'`x'_`t'>60 & codcom==32
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==32
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==32
	}	
}
}




*2021-2023
***********************
local e=2

**** Asada Moracia

foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen p`y'`x'_`q'=(2695+155*m3`y'`x')*`p`q''^`e' if m3`y'`x'<=10 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*30 +200*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==64

foreach t in 1 4{
	gen p1`y'`x'_`t'_`q'=(2695+155*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*30 +200*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==64
	gen s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==64
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==64
	}
}
}


/*
Paso Tempisque, Chomes, San Blas, Lepanto 


*/

foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3415+160*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*30 + 195*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3415+160*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*30 +195*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	}

}
}

**** Asada Jocotes

foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2745+150*m3`y'`x')*`p`q''^`e' if codcom==35

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2745+150*r`y'`x'_`t')*`p`q''^`e' if codcom==35
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==35
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==35
	}
}
}

**** Asada Lomas de Matapalo

foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3180+185*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*20+210*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==25 
replace p`y'`x'_`q'=(3180+185*10+195*20+210*30 +225*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==25 


foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(3180+185*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==25 
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*30 +225*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==25
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if codcom==25
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==25
	}
}

}

**** Asada Pueblo Nuevo

foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2800+190*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*20+215*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==47 
replace p`y'`x'_`q'=(2800+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==47 

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2800+190*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==47 
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==47
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==47
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==47
	}
}
}

**** Asada Santa Rita

foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3085+190*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==32

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3085+190*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==32
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==32
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==32
	}	
}
}




*2024-2025
**********

local e=3

**** Asada Moracia

foreach y in 2024 2025 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen p`y'`x'_`q'=(2695+155*m3`y'`x')*`p`q''^`e' if m3`y'`x'<=10 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*30 +200*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==64

foreach t in 1 4{
	gen p1`y'`x'_`t'_`q'=(2695+155*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*30 +200*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==64
	gen s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==64
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==64
	}
}
}


/*
Paso Tempisque, Chomes, San Blas, Lepanto 

*/

foreach y in 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3415+160*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*30 + 195*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3415+160*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*30 +195*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	}

}
}

**** Asada Jocotes

foreach y in 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2745+150*m3`y'`x')*`p`q''^`e' if codcom==35

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2745+150*r`y'`x'_`t')*`p`q''^`e' if codcom==35
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==35
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==35
	}
}
}

**** Asada Lomas de Matapalo


foreach y in 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3180+185*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*20+210*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==25 
replace p`y'`x'_`q'=(3180+185*10+195*20+210*30 +225*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==25 


foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(3180+185*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==25 
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*30 +225*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==25
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if codcom==25
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==25
	}
}

}

**** Asada Pueblo Nuevo

foreach y in 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2800+190*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*20+215*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==47 
replace p`y'`x'_`q'=(2800+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==47 

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2800+190*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==47 
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==47
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==47
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==47
	}
}
}

**** Asada Santa Rita


foreach y in 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3085+190*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==32

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3085+190*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==32
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==32
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==32
	}	
}
}


}


*Constructing different lifespans 

foreach y in 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen s`y'`x'_1_1_1=s`y'`x'_1_1
gen s`y'`x'_1_4_1=s`y'`x'_1_4
gen s`y'`x'_4_1_1=s`y'`x'_4_1
gen s`y'`x'_4_4_1=s`y'`x'_4_4
gen s`y'`x'_1_1_4=s`y'`x'_1_1
gen s`y'`x'_1_4_4=s`y'`x'_1_4
gen s`y'`x'_4_1_4=s`y'`x'_4_1
gen s`y'`x'_4_4_4=s`y'`x'_4_4
}
}



set more off


*Exchange rate 527 Colones is a Dollar
	*Investment in May 2015
	*I assume that everybody received treatment since June, not just the 4 communities. There is no reason to make to introduce the real timing.


*Difference of utility.
***********************

	local w1=0.125
	local w2=0.125
	local w3=0.125
	local w4=0.125
	local w5=0.125
	local w6=0.125
	local w7=0.125
	local w8=0.125	
	

	

	* Individuals: discount rate 30%, r=0.81
	****************************************

/* Method to get the CE (CE per period and then discount it). We collect savings since June 2015. */
	************************************************************
	
	*Analysis for certain case where r=0 and discount is the market one. 

	local r=0
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	*Manual change for (ii): Activate year 2020 if 5 years or 2025 if 10 years
	*local j=2020
	local j=2025
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	*discount rate g
	foreach g in 2 4 7 8 9 10 11 12 13 14 15 16 17 18 19 20{
	gen gain_`g'_`j'=0
	
	local i=1
	foreach x in 06 07 08 09 10 11 12{

	foreach a in 1 4{
			foreach b in 1 4{
				foreach c in 1 4{
			sum s2015`x'_`a'_`b'_`c'
			local diff_2015`x'_`a'_`b'_`c'=r(mean)*(1/527)

				}
			}
		}
	replace gain_`g'_`j'=gain_`g'_`j' + ((1/(1+`g'/100))^(`i'/12))*(((1-`r')*(`w1'*(`diff_2015`x'_1_1_1'^(1-`r'))/(1-`r') + `w2'*(`diff_2015`x'_1_4_1'^(1-`r'))/(1-`r') + `w3'*(`diff_2015`x'_4_1_1'^(1-`r'))/(1-`r') + `w4'*(`diff_2015`x'_4_4_1'^(1-`r'))/(1-`r')+`w5'*(`diff_2015`x'_1_1_4'^(1-`r'))/(1-`r') + `w6'*(`diff_2015`x'_1_4_4'^(1-`r'))/(1-`r') + `w7'*(`diff_2015`x'_4_1_4'^(1-`r'))/(1-`r') + `w8'*(`diff_2015`x'_4_4_4'^(1-`r'))/(1-`r')))^(1/(1-`r')))

	
	local i=`i'+1
	}
	
	

	

	local i=8
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	*Manual change for (ii): Activate period until 2020 if 5 years or until 2025 if 10 years
	*foreach y in 2016 2017 2018 2019 2020{
	foreach y in 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025{
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
	
	foreach a in 1 4{
			foreach b in 1 4{
				foreach c in 1 4{
			sum s`y'`x'_`a'_`b'_`c'
			local diff_`y'`x'_`a'_`b'_`c'=r(mean)*(1/527)

				}
			}
		}
	replace gain_`g'_`j'=gain_`g'_`j' + ((1/(1+`g'/100))^(`i'/12))*(((1-`r')*(`w1'*(`diff_`y'`x'_1_1_1'^(1-`r'))/(1-`r') + `w2'*(`diff_`y'`x'_1_4_1'^(1-`r'))/(1-`r') + `w3'*(`diff_`y'`x'_4_1_1'^(1-`r'))/(1-`r') + `w4'*(`diff_`y'`x'_4_4_1'^(1-`r'))/(1-`r')+`w5'*(`diff_`y'`x'_1_1_4'^(1-`r'))/(1-`r') + `w6'*(`diff_`y'`x'_1_4_4'^(1-`r'))/(1-`r') + `w7'*(`diff_`y'`x'_4_1_4'^(1-`r'))/(1-`r') + `w8'*(`diff_`y'`x'_4_4_4'^(1-`r'))/(1-`r')))^(1/(1-`r'))) if  `y'`x'<`j'06

	local i=`i'+1
	}
	}

	}
	
	
	

	
*Preparing table
matrix utd=J(16,1,.)
local i=1
*discount rate g
foreach g in 2 4 7 8 9 10 11 12 13 14 15 16 17 18 19 20{
	local k=1
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	*Manual change for (ii): Activate year 2020 if 5 years or 2025 if 10 years
	foreach z in 2025{
	*foreach z in 2020{
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	sum gain_`g'_`z'
	local m=r(mean)
	matrix utd[`i',`k']=`m'	

	}
	local i=`i'+1

}



matrix colnames utd = `j'years 
matrix rownames utd= d2 d4 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20

matrix list utd
 

